﻿<UserControl x:Class="TanmiaGrp.GeneralLedger.WinApp.Pages.ChartOfAccounts"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300">
    <UserControl.Resources>
        <ContextMenu x:Key="cmTree">
            <MenuItem Header="توسيع فروع الشجرة" />
            <MenuItem Header="طي فروع الشجرة" />
            <Separator />
            <MenuItem Header="اظهار رقم الحساب"
                      IsCheckable="True"
                      IsChecked="True" />
        </ContextMenu>
    </UserControl.Resources>
    <Grid Style="{StaticResource ContentRoot}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0"
               Content="دليل الحسابات" />
        <TextBox Grid.Row="1"
                 Name="txtSearchText"
                 TextChanged="OnSearchTextChanged" />
        <TreeView Name="tvAccounts"
                  Grid.Row="2"
                  SelectedItemChanged="OnSelectedAccountChanged"
                  DataContext="{Binding RelativeSource={RelativeSource Self}}">
            <TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter Property="IsSelected"
                            Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                    <Setter Property="IsExpanded"
                            Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
                    <Setter Property="FontWeight"
                            Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected"
                                 Value="True">
                            <Setter Property="FontWeight"
                                    Value="Bold" />
                        </Trigger>
                        <Trigger Property="IsSelected"
                                 Value="False">
                            <Setter Property="FontWeight"
                                    Value="Normal" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Path=AccountChildren}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=AccountNumber}" />
                        <TextBlock x:Name="d1"
                                   Text=" - " />
                        <TextBlock Text="{Binding Path=AccountName}" />
                    </StackPanel>
                    <HierarchicalDataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=AccountID}"
                                     Value="-1">
                            <Setter TargetName="d1"
                                    Property="Visibility"
                                    Value="Collapsed" />
                        </DataTrigger>
                    </HierarchicalDataTemplate.Triggers>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</UserControl>
